// MainDlg.h : interface of the CMainDlg class
//
/////////////////////////////////////////////////////////////////////////////

#pragma once
#include "PaintBkgnd.h"
//#include "CtrlColor.h"
#include "AtlBitmapSkinButton.h"
//#include "ButtonGif.h"
#define LEVEL_LOW 1
#define LEVEL_NOR 2
#define LEVEL_HIGH 3
#define LEVEL_VERY_HIGH 4

#define INVALID_INPUTFILE -1
#define CONVERT_FILED     -2

class CMainDlg : public CDialogImpl<CMainDlg>, public CUpdateUI<CMainDlg>,
		public CMessageFilter, public CIdleHandler, public CWinDataExchange<CMainDlg>,
		public CPaintBkgnd<CMainDlg, IDB_BITMAP1>
{
public:
	enum { IDD = IDD_MAINDLG };

	virtual BOOL PreTranslateMessage(MSG* pMsg);
	virtual BOOL OnIdle();

	BEGIN_UPDATE_UI_MAP(CMainDlg)
	END_UPDATE_UI_MAP()
	typedef CPaintBkgnd<CMainDlg,IDB_BITMAP1> CPaintBkgndBase;

//	typedef CCtrlColor<CMainDlg> CCtrlColorBase;


	BEGIN_MSG_MAP(CMainDlg)
		MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
		MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
		MESSAGE_HANDLER(WM_CONVERTFINISHED, OnConvertEnd)
		MESSAGE_HANDLER(WM_DROPFILES,OnDropFile)
		MESSAGE_HANDLER(WM_CLOSE,OnClose)
		MESSAGE_HANDLER(WM_SYSCOMMAND, OnSysCommand)
		COMMAND_ID_HANDLER(IDOK, OnOK)
		COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
		COMMAND_HANDLER(IDC_BUTTON_INPUT, BN_CLICKED, OnBnClickedButtonInput)
		COMMAND_HANDLER(IDC_BUTTON_OUTPUT, BN_CLICKED, OnBnClickedButtonOutput)
		COMMAND_HANDLER(IDC_RADIO_LOW, BN_CLICKED, OnBnClickedRadioLow)
		COMMAND_HANDLER(IDC_RADIO_NORMAL, BN_CLICKED, OnBnClickedRadioNormal)
		COMMAND_HANDLER(IDC_RADIO_HIGH, BN_CLICKED, OnBnClickedRadioHigh)
		COMMAND_HANDLER(IDC_RADIO_VERYHIGH, BN_CLICKED, OnBnClickedRadioVeryhigh)
		COMMAND_HANDLER(IDC_BUTTON_CONVERT, BN_CLICKED, OnBnClickedButtonConvert)		
		COMMAND_HANDLER(IDC_BUTTON_CLOSE, BN_CLICKED, OnBnClickedButtonClose)
		COMMAND_HANDLER(IDC_BUTTON_MIN, BN_CLICKED, OnBnClickedButtonMin)
		MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown)
		COMMAND_HANDLER(IDC_BUTTON_CONVERT2, BN_CLICKED, OnBnClickedButtonConvert2)
		CHAIN_MSG_MAP(CPaintBkgndBase)
		REFLECT_NOTIFICATIONS()
	END_MSG_MAP()

	BEGIN_DDX_MAP(CMainDlg)
		DDX_CONTROL_HANDLE(IDC_PROGRESS, m_wndProgressBar)
//		DDX_CONTROL_HANDLE(IDR_GIF1, m_gif)
		DDX_TEXT(IDC_EDIT_INPUT, m_sInputFile)	
		DDX_TEXT(IDC_EDIT_OUTPUT, m_sOutputFolder)	
		DDX_TEXT(IDC_STATIC_PROCESS,m_sProcess)
		
	END_DDX_MAP()

// Handler prototypes (uncomment arguments if needed):
//	LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
//	LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
//	LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)

	LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
	LRESULT OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
	LRESULT OnSysCommand(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
	LRESULT OnOK(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT OnClose(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
	LRESULT OnBnClickedButtonInput(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT OnBnClickedButtonOutput(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT OnBnClickedRadioLow(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT OnBnClickedRadioNormal(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT OnBnClickedRadioHigh(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT OnBnClickedRadioVeryhigh(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT OnBnClickedButtonConvert(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT OnConvertEnd(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
	LRESULT OnDropFile(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
	LRESULT OnEraseBkgnd(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/);
	LRESULT OnCtlColorStatic(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/);

	LRESULT OnBnClickedButtonClose(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT OnBnClickedButtonMin(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT OnLButtonDown(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
	LRESULT OnBnClickedButtonConvert2(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);

	void CloseDialog(int nVal);

protected:
	CString m_sInputFile;
	CString m_sInputTitle;
	CString m_sOutputFolder;
	CString m_sOutputFile;
	CString m_sFfmpegPath;
	CString m_sProcess;
	CString m_tipString1;
	CString m_tipString2;
	CString m_sVideoResolution;
	CString m_sVideoResolution_new;
	CString m_sConfigeFimePath;
	int		m_iVedioLevel;
	int		m_iBitRateNormal;
	int		m_iBitRateHigh;
	int		m_iBitRate;
	int		m_iMaxResolutionX;
	DWORD	m_dwMyExitCode;
	DWORD	m_dwExitCode_P;
	CProgressBarCtrl m_wndProgressBar;

	CAtlBitmapButton m_buttonConvert;
	CAtlBitmapButton m_buttonConvert2;
	CAtlBitmapButton m_buttonSelect1;
	CAtlBitmapButton m_buttonSelect2;
	CAtlBitmapButton m_buttonClose;
	CAtlBitmapButton m_buttonMin;

	PROCESS_INFORMATION m_piProcessInfo;
	HANDLE m_hThread;
	BOOL m_bConverting;
	BOOL m_bIsAudio;
	BOOL m_bNeedChangeResolution;
	BOOL m_bNeedConfig;
	BOOL m_bRunOnce;


//	CButtonGif	m_gif;

	
	DWORD	DoConvert();
	BOOL	CheckPath();
	void	SetWindowEnable(BOOL FLAG);
	BOOL	CancelConvert();

	static DWORD WINAPI PROC_DO_CONVERT(PVOID pClass);
	BOOL LoadResourceFile(LONG lResourceId, LPCTSTR lpszFileName);
	void UpdateBk( int id );
	BOOL GetFileInformation();
	BOOL GetConfig();
	BOOL KillProcessFromName(LPCSTR lpProcessName);

};
